/* -----------------------------------------------------------------------------
 * PROJECT    : net.lwf
 * FILE       : SightWordHandler.java
 *
 * HISTORY:
 * Date          Author                        Description
 * ----------------------------------------------------------------------------- 
 * Dec 12, 2008       Raghu Sarraff			       Created
 */
package lwf.handler.english;

import java.util.List;

import net.lwf.common.constant.ICommonConstant;
import net.lwf.handler.util.ImageHtml;
import net.lwf.handler.util.WordUtil;

import lwf.factory.WordData;
import lwf.handler.entities.english.word.Word;

/**
 * Type the class description here
 *  
 */
public class SightWordHandler extends WordHandler {
	
	private int start = 0;
	private int end = 0;
	private int level = 0;
	
	/**
	 * @param start
	 * @param end
	 * @param level
	 */
	public SightWordHandler(int start, int end, int level) {
		this.start = start;
		this.end = end;
		this.level = level;
		init();
	}
	
	public SightWordHandler(int start, int end) {
		this.start = start;
		this.end = end;
		init();
	}
	
    private void init() {
//    	List lstSwords 
//		  = (List) PropertyReader.getInstance().getSightWords().get(String.valueOf(this.level));
    	List lstSwords = null;
    	switch(this.level) {
    		case ICommonConstant.VERY_SIMPLE:
    			//Very Simple
    			lstSwords = WordData.getInstance().getVerySimpleWords();
    			break;
    		case ICommonConstant.SIMPLE:
    			//Simple
    			lstSwords = WordData.getInstance().getSimpleWords();
    			break;
    		case ICommonConstant.MEDUIM:
    			//Very Simple
    			lstSwords = WordData.getInstance().getMeduimWords();
    			break;
    		case ICommonConstant.ABOVE_MEDIUM:
    			//Simple
    			lstSwords = WordData.getInstance().getAboveMeduimWords();
    			break;
    		default:
    			//Hard
    			lstSwords = WordData.getInstance().getHardWords();
    	}
    	setDisplayData(start, end, lstSwords);
    }
    
//    protected String processRowData(Object obj) {
//    	StringBuffer sbPData = new StringBuffer();
//    	sbPData.append("<table border=\"0\" width=\"100%\" align=\"center\" cellspacing=\"0\" cellpadding=\"0\">");
//			String word = (String) obj;
//		    sbPData.append("<tr>");
//		        sbPData.append("<td width=\"5%\">");
//			        sbPData.append(ImageHtml.getBulletImage(1));
//		        sbPData.append("</td>");
//	   			sbPData.append("<td width=\"95%\">");
//	   				sbPData.append(getWordData(word));
//	   			sbPData.append("</td>");
//		    sbPData.append("</tr>");
//        	String sentence = WordUtil.getWordSentence(word);
//        	if(sentence.length() != 0) {
//			    sbPData.append("<tr>");
//					sbPData.append("<td colspan=\"2\" class=\"wordsentence\">");
//						sbPData.append("<b>Usage:</b> <br>" + sentence);
//					sbPData.append("</td>");
//			    sbPData.append("</tr>");	        		
//        	}
//        sbPData.append("</table>");
//        return sbPData.toString();
//    }
    
    protected String processRowData(Object obj) {
    	Word word = (Word) obj;
    	StringBuffer sbPData = new StringBuffer();
    	sbPData.append("<table border=\"0\" width=\"100%\" align=\"center\" cellspacing=\"0\" cellpadding=\"0\">");
		    sbPData.append("<tr>");
		        sbPData.append("<td width=\"5%\">");
			        sbPData.append(ImageHtml.getBulletImage(1));
		        sbPData.append("</td>");
	   			sbPData.append("<td width=\"95%\">");
	   				sbPData.append(WordUtil.getWordData(word.getName(), false));
	   			sbPData.append("</td>");
		    sbPData.append("</tr>");
        	String sentence = word.getSentence();
        	if(sentence != null && sentence.length() != 0) {
			    sbPData.append("<tr>");
					sbPData.append("<td colspan=\"2\" class=\"wordsentence\">");
						sbPData.append(sentence);
					sbPData.append("</td>");
			    sbPData.append("</tr>");	        		
        	}
        sbPData.append("</table>");
        return sbPData.toString();
    }    
    
}

